home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / nihcl-30.lha / nihcl-3.0 / ex / ex5-7.c < prev    next >
C/C++ Source or Header  |  1990-05-15  |  2KB  |  66 lines

  1. // ex5-7.c -- Find dates of working days
  2.  
  3. // $Header: /afs/alw.nih.gov/unix/sun4_40c/usr/local/src/nihcl-3.0/share/ex/RCS/ex5-7.c,v 3.0 90/05/15 22:45:32 kgorlen Rel $
  4.  
  5. #include "Date.h"
  6. #include "String.h"
  7.  
  8. bool isHoliday(const Date& day)
  9. {
  10.     const unsigned NUMHOLIDAYS = 10;    
  11.     int yr=day.year();
  12.     Date holiday[NUMHOLIDAYS];
  13.  
  14. // Generate the holidays
  15.  
  16. // New Year's Day
  17.     holiday[0] = Date(1,"Jan",yr);
  18. // M.L. King's b'day - Third Mon, Jan.
  19.     holiday[1] = (Date(21,"Jan",yr)).previous("Mon");
  20. // Washington's b'day - Third Mon., Feb.
  21.     holiday[2] = (Date(21,"Feb",yr)).previous("Mon");
  22. // Memorial Day - Last Mon., May
  23.     holiday[3] = (Date(31,"May",yr)).previous("Mon");
  24. // Independence Day
  25.     holiday[4] = Date(4,"July",yr);
  26. // Labor Day - First Mon., Sept.
  27.     holiday[5] = (Date(7,"Sept",yr)).previous("Mon");
  28. // Columbus Day - Second Mon., Oct.
  29.     holiday[6] = (Date(14,"Oct",yr)).previous("Mon");
  30. // Veteran's Day
  31.     holiday[7] = Date(11,"Nov",yr);
  32. // Thanksgiving - Fourth Thurs., Nov.
  33.     holiday[8] = (Date(28,"Nov",yr)).previous("Thur");
  34. // Christmas
  35.     holiday[9] = Date(25,"Dec",yr);
  36.  
  37. // See if day in question falls on a holiday
  38.  
  39.     register i;
  40.     for (i = 0; i<=NUMHOLIDAYS-1; i++)
  41.         if (day==holiday[i]) return YES;
  42.     return NO;  
  43. }
  44.  
  45. /*
  46. Find the dates for every specified day-of-the-week (e.g., Wed)
  47. after the specified date until the end of the year.
  48. */
  49. main ()
  50. {
  51.     Date date, day;
  52.     String day_of_week;
  53.  
  54.     cout << "Enter date:   ";
  55.     cin >> date;
  56.     cout << "Enter day of week:   ";
  57.     cin >> day_of_week;
  58.     day = (date+7).previous(day_of_week); // Exclude specified
  59.                                           // date
  60.     Date end_of_year(31,"Dec",date.year());
  61.     while(day.between(date,end_of_year)) {
  62.         if (!isHoliday(day)) cout << day << endl;
  63.         day = day+7;
  64.     }
  65. }
  66.